package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.MemberClient;
import cn.wolfcode.crm.query.MemberQueryObject;
import cn.wolfcode.crm.serivce.IMemberClientService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("memberClient")
public class MemberClientController {
    @Autowired
    private IMemberClientService service;

    @RequestMapping("view")
    @RequiresPermissions(value={"memberClient:view","会员明细界面"},logical = Logical.OR)
    public String view() throws Exception {
        return "memberClient";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(MemberQueryObject qo) throws Exception {
        PageResult query = service.query(qo);
        return query;
    }


    //删除会员
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) throws Exception {
        try {
            service.deleteByPrimaryKey(id);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("操作失败!");
        }
    }

    //验证用户名的方法
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    @RequiresPermissions(value={"memberClient:saveOrUpdate","会员新增/编辑"},logical = Logical.OR)
    public JSONResult query(MemberClient emp) throws Exception {
        try {
            service.saveOrUpdate(emp);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("保存失败!");
        }
    }

}
